import { DeviceStatus } from '../../../constants/device';

/**
 * 校验表单信息是否合法
 * @param {object} form 表单信息
 */
export function validateForm(form) {
  if (!form.name) return '请填写设备名称';
  if (!form.typeUuid) return '请填写设备类型';
  if (!form.serialNumber) return '请填写序列号';
  if (!form.latitude) return '请填写经纬度';
  if (!form.longitude) return '请填写经纬度';
  if (!form.location) return '请填写设备地址';
}

/**生成设备状态别下拉列表可选数据*/
export function generateSelectorData() {
  const result = [{ value: '', label: '全部' }];
  Object.values(DeviceStatus).forEach(status => {
    result.push({ value: status, label: getDisplay(status) });
  });

  return result;
}

/**
 * 获取设备状态显示内容
 * @param {string} status 设备状态
 */
export function getDisplay(status) {
  switch (status) {
    case DeviceStatus.Unknown:
      return '未知';
    case DeviceStatus.Normal:
      return '正常/在线';
    case DeviceStatus.Abnormal:
      return '告警';
    case DeviceStatus.OnCheck:
      return '临检';
    case DeviceStatus.Offline:
      return '离线';
    default:
      return '未知级别';
  }
}

export function getStatusColor(status) {
  switch (status) {
    case DeviceStatus.Unknown:
      return '#10aeff';
    case DeviceStatus.Normal:
      return '#07c160';
    case DeviceStatus.Abnormal:
      return '#fa5151';
    case DeviceStatus.OnCheck:
      return '#ffc300';
    case DeviceStatus.Offline:
      return '#aaa';
    default:
      return '#fff';
  }
}

const ActiveList = {
  activeTrue: true,
  activeFalse: false
};

export function getActiveSelector() {
  const result = [];
  Object.values(ActiveList).forEach(active => {
    result.push({ value: active, label: getActiveDisplay(active) });
  });
  return result;
}

export function getActiveDisplay(active) {
  switch (active) {
    case ActiveList.activeTrue:
      return '启用';
    case ActiveList.activeFalse:
      return '不启用';
    default:
      return '未知';
  }
}

export function getActiveColor(active) {
  switch (active) {
    case ActiveList.activeTrue:
      return '#07c160';
    case ActiveList.activeFalse:
      return '#fa5151';
    default:
      return '#fff';
  }
}
